package com.jinzhi.jzweb.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.InvoiceorderDO;
import com.jinzhi.jzweb.service.InvoiceorderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;

/**
 * 
 * <pre>
 * 发票订单信息
 * </pre>
 * <small> 2019-12-11 16:05:16 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/invoiceorder")
public class InvoiceorderController extends BaseController {
	@Autowired
	private InvoiceorderService invoiceorderService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:invoiceorder:invoiceorder")
	String Invoiceorder(){
	    return "jzweb/invoiceorder/invoiceorder";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:invoiceorder:invoiceorder")
	public Result<Page<InvoiceorderDO>> list(InvoiceorderDO invoiceorderDTO){
        Wrapper<InvoiceorderDO> wrapper = new EntityWrapper<InvoiceorderDO>().orderBy("id", false);
        //wrapper.eq("name","jzweb");
        Page<InvoiceorderDO> page = invoiceorderService.selectPage(getPage(InvoiceorderDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:invoiceorder:add")
	String add(){
	    return "jzweb/invoiceorder/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:invoiceorder:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		InvoiceorderDO invoiceorder = invoiceorderService.selectById(id);
		model.addAttribute("invoiceorder", invoiceorder);
	    return "jzweb/invoiceorder/edit";
	}
	
	@Log("添加发票订单信息")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:invoiceorder:add")
	public Result<String> save( InvoiceorderDO invoiceorder){
		invoiceorder.setUid(1L);
		invoiceorder.setOrderId("1");
		invoiceorder.setInvoiceId(1L);
		Date date = new Date();
		invoiceorder.setCreateDate(date);
		invoiceorder.setCreator(this.getUsername());
		invoiceorder.setUpdateDate(date);
		invoiceorder.setUpdater(this.getUsername());
		boolean save = invoiceorderService.insert(invoiceorder);
		return save ? Result.ok() : Result.fail();
	}
	
	@Log("修改发票订单信息")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:invoiceorder:edit")
	public Result<String>  update( InvoiceorderDO invoiceorder){
		boolean update = invoiceorderService.updateById(invoiceorder);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除发票订单信息")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:invoiceorder:remove")
	public Result<String>  remove( Integer id){
		invoiceorderService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除发票订单信息")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:invoiceorder:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] ids){
		invoiceorderService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}

}
